<?php

class cache {
    var $valid=false;
    var $filename=NULL;

    function cache($filename, $timelimit) {

        global $properties;

        $this->filename=$properties['cache_dir'].$filename.".inc.tpl";

        if (file_exists($this->filename)) {
            $time_diff=time()-filemtime($this->filename);
            if ($time_diff<$timelimit) {
                $this->valid=true;
            }
            else
            {
                $this->valid=false;
                ob_start();
            }
        }
    }

    function writeCache() {
        if ($this->filename) {
            $content=ob_get_contents();
            ob_clean();
            $cache_file=fopen($this->filename,'w');
            fwrite($cache_file, $content);
            fclose($cache_file);
        }
    }
}
?>
